import 'package:flutter/cupertino.dart';

class CustomNavigatorObserver extends NavigatorObserver {
  factory CustomNavigatorObserver() => _getInstance();

  static CustomNavigatorObserver get instance => _getInstance();
  static CustomNavigatorObserver? _instance;

  BuildContext? curContext;

//tabbar 里面的几个主页面,返回的是 根据索引进行上报
  CustomNavigatorObserver._internal();

  static CustomNavigatorObserver _getInstance() {
    if (_instance == null) {
      _instance = new CustomNavigatorObserver._internal();
    }
    return _instance!;
  }

  String topRouteName = "";

  void didPush(Route<dynamic>? route, Route<dynamic>? previousRoute) {
    notifyHide(previousRoute);
    notifyShow(route);
  }

  void didPop(Route<dynamic>? route, Route<dynamic>? previousRoute) {
    notifyHide(route);
    notifyShow(previousRoute);
  }

  void didRemove(Route<dynamic>? route, Route<dynamic>? previousRoute) {
    notifyHide(route);
    notifyShow(previousRoute);
  }

  /// The [Navigator] replaced `oldRoute` with `newRoute`.
  void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
    notifyHide(oldRoute);
    notifyShow(newRoute);
  }

  void notifyShow(Route<dynamic>? route) {
    if (route != null) {
      if (![null, "", "null"].contains(route.settings.name.toString())) {
        if (route.settings.name == '/') {
        } else {

        }
      }
    }
  }

  void notifyHide(Route<dynamic>? route) {
    if (route != null) {
      if (![null, "", "null"].contains(route.settings.name.toString())) {
        if (route.settings.name == '/') {
        } else {

        }
      }
    }
  }
}
